﻿@page "/RawPage"
@inject RawfoilmachinesServer rawfoilmachinesServer
@using System.ComponentModel
@using AntDesign.TableModels
@inject ModalService _modalService
@inject MessageService _message
<h3>生箔下料</h3>
<div>
    <Row>
        <Col Span="24">请选择生箔机编号</Col>
    </Row>
    <Row>
        <Col Span="24">
        <Select style="width:100%" DataSource="@Rawfoilmachines"
                AllowClear="true"
                ValueOnClear="@(0)"
                @bind-Value="@Rawfoilmachineselet"
                ValueName="@nameof(Rawfoilmachine_Entity.Deviceid)"
                LabelName="@nameof(Rawfoilmachine_Entity.Remark)">
        </Select>
        </Col>
    </Row>
    <Row>
        <Col  Span="24"> <label >请选择[取空卷]缓存架</label></Col>
    </Row>
    <Row>
        <Col Span="24">
        <Select style="width:100%" DataSource="@EmptyCaches"
                AllowClear="true"
                ValueOnClear="@(0)"
                @bind-Value="@EmptyCacheselet"
                ValueName="@nameof(EmptyCache_Entity.Deviceid)"
                LabelName="@nameof(EmptyCache_Entity.Remark)">
        </Select>
        </Col>
    </Row>
    <Row>
        <Col Span="24"> <label >请选择[放满卷]缓存架</label></Col>
    </Row>
    <Row>
        <Col Span="24">
        <Select style="width:100%" DataSource="@FullCaches"
                AllowClear="true"
                ValueOnClear="@(0)"
                @bind-Value="@FullCacheselet"
                ValueName="@nameof(FullCache_Entity.Deviceid)"
                LabelName="@nameof(FullCache_Entity.Remark)">
        </Select>
        </Col>
    </Row>
    <Row>
        <Col Span="24">
        <label>烘箱号</label>
        </Col>
    </Row>
    <Row>
        <Col Span="24">
        <Input style="width:100%" Placeholder="Basic usage" @bind-Value="@index" />
        </Col>
    </Row>
    <Row>
        <Col Span="24">
        <label>工位号</label>
        </Col>
    </Row>
    <Row>
        <Col Span="24">
        <Input style="width:100%" Placeholder="Basic usage" @bind-Value="@gw" />
        </Col>
    </Row>
    <Row>
        <Col Span="24">
        <label>是否指定缓存架</label>
        </Col>
    </Row>
    <Row>
        <Col Span="8" Push="8">
        <Switch style="width:100%" @bind-Value="@Flag"></Switch>
        </Col>
    </Row>
    <br>
 @*  <Row>
        <Col Span="24">
        <Button style="width:100%" Type="@ButtonType.Primary" @onclick="@Creat">生箔下卷，进烘箱</Button>
        </Col>
    </Row>
    <br>*@

   @* <Row>
        <Col Span="24">
        <Button style="width:100%" Type="@ButtonType.Primary" @onclick="@Creatnobaked">生箔下料，无需烘烤</Button>
        </Col>
    </Row>
    <br>*@

    @*生箔下卷,暂无可用烘箱，生箔下卷，放缓存架*@
    <Row>
        <Col Span="24">
        <Button style="width:100%" Type="@ButtonType.Primary" @onclick="@Creatnotobebaked">生箔下料，放缓存架</Button>
        </Col>
    </Row>
</div>

@code {
    ObservableCollection<Rawfoilmachine_Entity> Rawfoilmachines { get; set; } = new ObservableCollection<Rawfoilmachine_Entity>();
    ObservableCollection<EmptyCache_Entity> EmptyCaches { get; set; } = new ObservableCollection<EmptyCache_Entity>();
    ObservableCollection<FullCache_Entity> FullCaches { get; set; } = new ObservableCollection<FullCache_Entity>();
    int Rawfoilmachineselet { get; set; } = 0;
    int EmptyCacheselet { get; set; } = 0;
    int FullCacheselet { get; set; } = 0;
    bool Flag { get; set; } = true;
    int index { get; set; } = 0;
    int gw { get; set; } = 0;

    protected override async Task OnInitializedAsync()
    {
        var rawfoilmachines = await rawfoilmachinesServer.GetRawfoilmachine();
        if (rawfoilmachines!=null)
        {
            Rawfoilmachines.Clear();
            foreach (var item in rawfoilmachines)
            {
                Rawfoilmachines.Add(item);
            }
        }
        var emptyCaches = await rawfoilmachinesServer.GetEmpty();
        if (emptyCaches!=null )
        {
            EmptyCaches.Clear();
            foreach (var item in emptyCaches)
            {
                EmptyCaches.Add(item);
            }
        }

        var fullCaches = await rawfoilmachinesServer.GetFull();
        if (fullCaches != null)
        {
            FullCaches.Clear();
            foreach (var item in fullCaches)
            {
                FullCaches.Add(item);
            }
        }

        base.OnInitialized();
    }
    private async Task Creat()
    {
        _modalService.Confirm(new ConfirmOptions()
        {
            Title = "提示",
            Icon =@<Icon Type="exclamation-circle" Theme="Outline"></Icon>,
            Content = "是否提交？",
            OkText = "确认",
            OnOk = async (e) =>
            {
                if (Flag)
                {
                    int a = Rawfoilmachineselet;
                    int c = index;
                    var aa = await rawfoilmachinesServer.TaskCreat(Rawfoilmachineselet, index,gw, EmptyCacheselet);
                    _message.Info(aa);
                }
                else
                {
                    int a = Rawfoilmachineselet;
                    int c = index;
                    var aa = await rawfoilmachinesServer.TaskCreat(Rawfoilmachineselet, index,gw);
                    _message.Info(aa);
                }

            },
            CancelText = "取消"
        });


    }

    private async Task Creatnobaked()
    {
        _modalService.Confirm(new ConfirmOptions()
        {
            Title = "提示",
            Icon =@<Icon Type="exclamation-circle" Theme="Outline"></Icon>,
            Content = "是否提交？",
            OkText = "确认",
            OnOk = async (e) =>
            {
                if (Flag)
                {
                    int a = Rawfoilmachineselet;
                    int c = index;
                    var aa = await rawfoilmachinesServer.TaskCreatnobaked(Rawfoilmachineselet, EmptyCacheselet, FullCacheselet);
                    _message.Info(aa);
                }
                else {
                    int a = Rawfoilmachineselet;
                    int c = index;
                    var aa = await rawfoilmachinesServer.TaskCreatnobaked(Rawfoilmachineselet);
                    _message.Info(aa);
                }

            },
            CancelText = "取消"
        });


    }

    private async Task Creatnotobebaked()
    {
        _modalService.Confirm(new ConfirmOptions()
        {
            Title = "提示",
            Icon =@<Icon Type="exclamation-circle" Theme="Outline"></Icon>,
            Content = "是否提交？",
            OkText = "确认",
            OnOk = async (e) =>
            {
                if (Flag)
                {
                    int a = Rawfoilmachineselet;
                    int c = index;
                    var aa = await rawfoilmachinesServer.TaskCreattobebake(Rawfoilmachineselet,EmptyCacheselet,FullCacheselet);
                    _message.Info(aa);
                }
                else
                {
                    int a = Rawfoilmachineselet;
                    int c = index;
                    var aa = await rawfoilmachinesServer.TaskCreattobebake(Rawfoilmachineselet);
                    _message.Info(aa);
                }

            },
            CancelText = "取消"
        });


    }

}
